/* eslint-disable no-unused-vars */
/* eslint-disable react/destructuring-assignment */
/* eslint-disable no-useless-constructor */
/* eslint-disable react/no-find-dom-node  */
import React from 'react';
import ReactDom from 'react-dom';

/**
 * 大小改变自适应控件
 */
class Resize extends React.Component {
  constructor(props) {
    super(props);
  }

  async componentDidMount() {
    this.resizeObserver = new ResizeObserver((entries) => {
      entries.forEach((entrie) => {
        this.props.onChange(entrie);
      });
    });
    const dom = ReactDom.findDOMNode(this);
    this.resizeObserver.observe(dom);
  }

  componentWillUnmount() {
    this.resizeObserver.disconnect();
  }

  render() {
    return <div {...this.props}>{this.props.children}</div>;
  }
}

export default Resize;
